package com.lieve;

import com.lieve.entity.Blog;
import com.lieve.mapper.BlogMapper;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.Configuration;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

import java.io.IOException;
import java.io.InputStream;

/**
 * @author sunlijiang
 * @date 2020/4/11
 */
public class XmlMain {

    public static void main(String[] args) {
        String resource = "mybatis-config.xml";
        try {
            InputStream inputStream = Resources.getResourceAsStream(resource);
            SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(inputStream);
            Configuration configuration = sqlSessionFactory.getConfiguration();
            configuration.addMapper(BlogMapper.class);
            SqlSession sqlSession = sqlSessionFactory.openSession();
            Blog blog = sqlSession.selectOne("com.lieve.mapper.BlogMapper.getById", 1L);
            System.out.println(blog);
        } catch (IOException e) {
            e.printStackTrace();
        }

    }
}
